#include "serialize/miscdata.h"

//miscData definition
MiscData::MiscData()
{
//    energy_recover_time;
//    ammo_recover_time;
//    free_speak_times;
//    treasure_compose_time;
//    displayed_enemies;
//    displayed_messages;
//    strengthen_needed_money;
//    equip_dropped_probability;
//    get_treasure_probability;
//    day_invites;
//    day_messages_to_leave;
//    generals_upper;
//    weapons_upper;
//    armors_upper;
//    horses_upper;
//    treasure_upper;

//    cnt_player;
//    level_exp_player;
//    energy_upper;
//    ammo_upper;
//    team_upper;
//    friend_upper;
//    cnt_other;
//    level_exp_other;

    energy_recover_time = 0;
    ammo_recover_time = 0;
    free_speak_times = 0;
    treasure_compose_time = 0;
    displayed_enemies = 0;
    displayed_expeditions = 0;
    displayed_messages = 0;
    strengthen_needed_money = 0;
    equip_dropped_probability = 0;
    get_treasure_probability = 0;
    day_invites = 0;
    day_messages_to_leave = 0;
    generals_upper = 0;
    weapons_upper = 0;
    armors_upper = 0;
    horses_upper = 0;
    treasure_upper = 0;

    cnt_player = 0;
    level_exp_player = 0;
    energy_upper = 0;
    ammo_upper = 0;
    team_upper = 0;
    friend_upper = 0;
    cnt_other = 0;
    level_exp_other = 0;

}

//MiscData::MiscData(qint32 _cnt_player, qint32 *_level_exp_player, qint32 _cnt_other, qint32 *_level_exp_other)
//{
//    cnt_player = _cnt_player;
//    if(level_exp_player!=0)
//        delete[] level_exp_player;
//    level_exp_player = new qint32[cnt_player];
//    for(int i=0;i<cnt_player;i++)
//        level_exp_player[i] = _level_exp_player[i];

//    cnt_other = _cnt_other;
//    if(level_exp_other!=0)
//        delete[] level_exp_other;
//    level_exp_other = new qint32[cnt_other];
//    for(int i=0;i<cnt_other;i++)
//        level_exp_other[i] = _level_exp_other[i];
//}

MiscData::MiscData(const MiscData& e)
{
    energy_recover_time = e.energy_recover_time;
    ammo_recover_time = e.ammo_recover_time;
    free_speak_times = e.free_speak_times;
    treasure_compose_time = e.treasure_compose_time;
    displayed_enemies = e.displayed_enemies;
    displayed_expeditions = e.displayed_expeditions;
    displayed_messages = e.displayed_messages;
    strengthen_needed_money = e.strengthen_needed_money;
    equip_dropped_probability = e.equip_dropped_probability;
    get_treasure_probability = e.get_treasure_probability;
    day_invites = e.day_invites;
    day_messages_to_leave = e.day_messages_to_leave;
    generals_upper = e.generals_upper;
    weapons_upper = e.weapons_upper;
    armors_upper = e.armors_upper;
    horses_upper = e.horses_upper;
    treasure_upper = e.treasure_upper;

//    cnt_player;
//    level_exp_player;
//    energy_upper;
//    ammo_upper;
//    team_upper;
//    friend_upper;

    cnt_player = e.cnt_player;
    if(level_exp_player!=0)
        delete[] level_exp_player;
    if(energy_upper!=0)
        delete[] energy_upper;
    if(ammo_upper!=0)
        delete[] ammo_upper;
    if(team_upper!=0)
        delete[] team_upper;
    if(friend_upper!=0)
        delete[] friend_upper;
    level_exp_player = new qint32[cnt_player];
    energy_upper = new qint32[cnt_player];
    ammo_upper = new qint8[cnt_player];
    team_upper = new qint8[cnt_player];
    friend_upper = new qint8[cnt_player];
    for(int i=0;i<cnt_player;i++)
    {
        level_exp_player[i] = e.level_exp_player[i];
        energy_upper[i] = e.energy_upper[i];
        ammo_upper[i] = e.ammo_upper[i];
        team_upper[i] = e.team_upper[i];
        friend_upper[i] = e.friend_upper[i];
    }

    cnt_other = e.cnt_other;
    if(level_exp_other!=0)
        delete[] level_exp_other;
    level_exp_other = new qint32[cnt_other];
    for(int i=0;i<cnt_other;i++)
        level_exp_other[i] = e.level_exp_other[i];
}

MiscData& MiscData::operator=(const MiscData& e)
{
    if(&e == this)
        return *this;

    energy_recover_time = e.energy_recover_time;
    ammo_recover_time = e.ammo_recover_time;
    free_speak_times = e.free_speak_times;
    treasure_compose_time = e.treasure_compose_time;
    displayed_enemies = e.displayed_enemies;
    displayed_expeditions = e.displayed_expeditions;
    displayed_messages = e.displayed_messages;
    strengthen_needed_money = e.strengthen_needed_money;
    equip_dropped_probability = e.equip_dropped_probability;
    get_treasure_probability = e.get_treasure_probability;
    day_invites = e.day_invites;
    day_messages_to_leave = e.day_messages_to_leave;
    generals_upper = e.generals_upper;
    weapons_upper = e.weapons_upper;
    armors_upper = e.armors_upper;
    horses_upper = e.horses_upper;
    treasure_upper = e.treasure_upper;

//    cnt_player;
//    level_exp_player;
//    energy_upper;
//    ammo_upper;
//    team_upper;
//    friend_upper;

    cnt_player = e.cnt_player;
    if(level_exp_player!=0)
        delete[] level_exp_player;
    if(energy_upper!=0)
        delete[] energy_upper;
    if(ammo_upper!=0)
        delete[] ammo_upper;
    if(team_upper!=0)
        delete[] team_upper;
    if(friend_upper!=0)
        delete[] friend_upper;
    level_exp_player = new qint32[cnt_player];
    energy_upper = new qint32[cnt_player];
    ammo_upper = new qint8[cnt_player];
    team_upper = new qint8[cnt_player];
    friend_upper = new qint8[cnt_player];
    for(int i=0;i<cnt_player;i++)
    {
        level_exp_player[i] = e.level_exp_player[i];
        energy_upper[i] = e.energy_upper[i];
        ammo_upper[i] = e.ammo_upper[i];
        team_upper[i] = e.team_upper[i];
        friend_upper[i] = e.friend_upper[i];
    }

    cnt_other = e.cnt_other;
    if(level_exp_other!=0)
        delete[] level_exp_other;
    level_exp_other = new qint32[cnt_other];
    for(int i=0;i<cnt_other;i++)
        level_exp_other[i] = e.level_exp_other[i];

    return *this;
}

MiscData::~MiscData()
{
    if(level_exp_player!=0)
        delete[] level_exp_player;
    if(energy_upper!=0)
        delete[] energy_upper;
    if(ammo_upper!=0)
        delete[] ammo_upper;
    if(team_upper!=0)
        delete[] team_upper;
    if(friend_upper!=0)
        delete[] friend_upper;
    if(level_exp_other!=0)
        delete[] level_exp_other;
}

ostream& operator <<(ostream& os,MiscData& e)
{
    os<<"******start******"<<endl;
    os<<"MiscData info:"<<endl;

    os<<"energy_recover_time:"<<(int)e.energy_recover_time<<endl;
    os<<"ammo_recover_time:"<<(int)e.ammo_recover_time<<endl;
    os<<"free_speak_times:"<<(int)e.free_speak_times<<endl;
    os<<"treasure_compose_time:"<<(int)e.treasure_compose_time<<endl;
    os<<"displayed_enemies:"<<(int)e.displayed_enemies<<endl;
    os<<"displayed_messages:"<<(int)e.displayed_messages<<endl;
    os<<"displayed_expeditions:"<<(int)e.displayed_expeditions<<endl;
    os<<"strengthen_needed_money:"<<(int)e.strengthen_needed_money<<endl;
    os<<"equip_dropped_probability:"<<(int)e.equip_dropped_probability<<endl;
    os<<"get_treasure_probability:"<<(int)e.get_treasure_probability<<endl;
    os<<"day_invites:"<<(int)e.day_invites<<endl;
    os<<"day_messages_to_leave:"<<(int)e.day_messages_to_leave<<endl;
    os<<"generals_upper:"<<(int)e.generals_upper<<endl;
    os<<"weapons_upper:"<<(int)e.weapons_upper<<endl;
    os<<"armors_upper:"<<(int)e.armors_upper<<endl;
    os<<"horses_upper:"<<(int)e.horses_upper<<endl;
    os<<"treasure_upper:"<<(int)e.treasure_upper<<endl;

    os<<"expCurvePlayer:"<<(int)e.cnt_player<<" levels!"<<endl;
    for(qint32 i=0;i<e.cnt_player;i++)
        os<<(int)e.level_exp_player[i]<<"  ";
    os<<endl;
    for(qint32 i=0;i<e.cnt_player;i++)
        os<<(int)e.energy_upper[i]<<"  ";
    os<<endl;
    for(qint32 i=0;i<e.cnt_player;i++)
        os<<(int)e.ammo_upper[i]<<"  ";
    os<<endl;
    for(qint32 i=0;i<e.cnt_player;i++)
        os<<(int)e.team_upper[i]<<"  ";
    os<<endl;
    for(qint32 i=0;i<e.cnt_player;i++)
        os<<(int)e.friend_upper[i]<<"  ";
    os<<endl;
    os<<"expCurveOther:"<<(int)e.cnt_other<<" levels!"<<endl;
    for(qint32 i=0;i<e.cnt_other;i++)
        os<<(int)e.level_exp_other[i]<<"  ";
    os<<endl;

    os<<"******end******"<<endl;

    return os;
}

QDataStream& operator<<(QDataStream& ds,MiscData& e)
{
    ds<<e.energy_recover_time;
    ds<<e.ammo_recover_time;
    ds<<e.free_speak_times;
    ds<<e.treasure_compose_time;
    ds<<e.displayed_enemies;
    ds<<e.displayed_expeditions;
    ds<<e.displayed_messages;
    ds<<e.strengthen_needed_money;
    ds<<e.equip_dropped_probability;
    ds<<e.get_treasure_probability;
    ds<<e.day_invites;
    ds<<e.day_messages_to_leave;
    ds<<e.generals_upper;
    ds<<e.weapons_upper;
    ds<<e.armors_upper;
    ds<<e.horses_upper;
    ds<<e.treasure_upper;

    ds<<e.cnt_player;
    for(qint32 i=0;i<e.cnt_player;i++)
    {
        ds<<e.level_exp_player[i];
        ds<<e.energy_upper[i];
        ds<<e.ammo_upper[i];
        ds<<e.team_upper[i];
        ds<<e.friend_upper[i];
    }
    ds<<e.cnt_other;
    for(qint32 i=0;i<e.cnt_other;i++)
        ds<<e.level_exp_other[i];

    return ds;
}

QDataStream& operator>>(QDataStream& ds,MiscData& e)
{
    ds>>e.energy_recover_time;
    ds>>e.ammo_recover_time;
    ds>>e.free_speak_times;
    ds>>e.treasure_compose_time;
    ds>>e.displayed_enemies;
    ds>>e.displayed_expeditions;
    ds>>e.displayed_messages;
    ds>>e.strengthen_needed_money;
    ds>>e.equip_dropped_probability;
    ds>>e.get_treasure_probability;
    ds>>e.day_invites;
    ds>>e.day_messages_to_leave;
    ds>>e.generals_upper;
    ds>>e.weapons_upper;
    ds>>e.armors_upper;
    ds>>e.horses_upper;
    ds>>e.treasure_upper;

    ds>>e.cnt_player;
    if(e.level_exp_player!=0)
        delete[] e.level_exp_player;
    if(e.energy_upper!=0)
        delete[] e.energy_upper;
    if(e.ammo_upper!=0)
        delete[] e.ammo_upper;
    if(e.team_upper!=0)
        delete[] e.team_upper;
    if(e.friend_upper!=0)
        delete[] e.friend_upper;
    e.level_exp_player = new qint32[e.cnt_player];
    e.energy_upper = new qint32[e.cnt_player];
    e.ammo_upper = new qint8[e.cnt_player];
    e.team_upper = new qint8[e.cnt_player];
    e.friend_upper = new qint8[e.cnt_player];
    for(qint32 i=0;i<e.cnt_player;i++)
    {
        ds>>e.level_exp_player[i];
        ds>>e.energy_upper[i];
        ds>>e.ammo_upper[i];
        ds>>e.team_upper[i];
        ds>>e.friend_upper[i];
    }
    ds>>e.cnt_other;
    if(e.level_exp_other!=0)
        delete[] e.level_exp_other;
    e.level_exp_other = new qint32[e.cnt_other];
    for(qint32 i=0;i<e.cnt_other;i++)
        ds>>e.level_exp_other[i];

    return ds;
}
